﻿#ifndef FILESENDER_H
#define FILESENDER_H

#include <QObject>
#include <QUdpSocket>
#include <QFile>
#include <QHostAddress>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define TSample 70  // 采样间隔 单位ns

// CAT240 消息长度
// 64字节头，1024字节视频数据，3字节时间数据
#define CAT240_LEN (32 + 8192 + 3)

static unsigned char spx_msg[64*1024];

class QTimer;

class FileSender : public QObject {
    Q_OBJECT

public:
    explicit FileSender(const QHostAddress &groupAddress, quint16 port, QObject *parent = nullptr);
    ~FileSender();

    void startSending(QString &filePath);
    unsigned char* spx_video = new unsigned char[8192]; // 动态分配内存
    int Wave2Cat240(unsigned int div_num, unsigned int bearing, unsigned char* wave, int wave_len, unsigned char** spx_video);
private slots:
    void sendNextPacket();

private:
    QFile *m_file=NULL;
    QUdpSocket m_socket;
    QHostAddress m_groupAddress;
    quint16 m_port;
    qint64 m_packetSequenceNumber;

    QTimer *m_timer; // 用于成员变量的生命周期管理
};

#endif // FILESENDER_H
